/************************************************************
**
** Application: CJLib
**
** Title:       h.draw
**
*************************************************************/

#ifndef DRAWL___H
#define DRAWL___H


#include "oslib/draw.h"
#include "oslib/drawfile.h"


#define DEVICE_VDU      0
#define DEVICE_PRINTER  1
#define DEVICE_DRAWFILE 2



/* path component ids */
#define SUBPATH_END   0
#define SUBPATH_MOVE  2
#define SUBPATH_CLOSE 5
#define SUBPATH_DRAW  8
#define SUBPATH_BEZIER 6

#define ADD_HEADER TRUE
#define NO_HEADER  FALSE

#define CHECK_BUFFER TRUE
#define NO_CHECK     FALSE

#define OS_UNITS     TRUE
#define DRAW_UNITS   FALSE

typedef struct DrawL_buffer_details
{
  char *vdu;
  int   vdu_length;
  int   vdu_chunk;
  int   vdu_extend;
  char *draw;
  int   draw_length;
  int   draw_chunk;
  int   draw_extend;
} DrawL_buffer_details;



enum dashpattern
{
  DASHP_SOLID,
  DASHP_DOT,
  DASHP_DASH,
  DASHP_DOTDASH,
  DASHP_OPENDOT,
  DASHP_WIDEOPENDOT,
  DASHP_LONGDASH,
  DASHP_OPENDOTDASH,
  DASHP_LONGDOTDASH,
  DASHP_SHORTDOTDASH,
  DASHP_OPENDASH,
  DASHP_DOTDOTDASH,
  DASHP_SHORTDOT
};



typedef struct dash_def
{
  int  start;
  int  components;
  int  element[12];
} dash_def;


typedef struct path_comp_no_arg
{
  int comp_id;
} path_comp_no_arg;

typedef struct subpath_onearg
{
  int id;
  int x;
  int y;
} subpath_onearg;

typedef struct path_comp_one_arg
{
  int comp_id;
  int x;
  int y;
} path_comp_one_arg;

typedef struct path_four_comp
{
  subpath_onearg c1;
  subpath_onearg c2;
  subpath_onearg c3;
  subpath_onearg c4;
} path_four_comp;

typedef struct path_four_comp_closed
{
  subpath_onearg c1;
  subpath_onearg c2;
  subpath_onearg c3;
  subpath_onearg c4;
  int close;
} path_four_comp_closed;

typedef struct path_comp_line
{
  subpath_onearg mv;
  subpath_onearg dr;
} path_comp_line;

typedef struct path_rectangle
{
  subpath_onearg mv;
  subpath_onearg d1;
  subpath_onearg d2;
  subpath_onearg d3;
  subpath_onearg d4;
} path_rectangle;

typedef struct path_rectangle_closed
{
  subpath_onearg mv;
  subpath_onearg d1;
  subpath_onearg d2;
  subpath_onearg d3;
  subpath_onearg d4;
  int close;
} path_rectangle_closed;

typedef struct path_comp_bez
{
  int comp_id;
  int x1;
  int y1;
  int cx1;
  int cy1;
  int cx2;
  int cy2;
} path_comp_bez;

typedef struct draw_settings
{
  int device;
  char **buffer;
  int buf_length;
  int buf_offset;
  char *obj_start;
  os_colour line_colour;
  int line_width;
  os_colour fill_colour;
  int text_fgnd;
  int text_bkgnd;
  draw_line_style   *line_style;
  draw_dash_pattern *dash_pattern;
} draw_settings;


typedef osbool (*allocfn)(draw_settings *dpars, int needed);  /* external function */


/* exported variables */

extern DrawL_buffer_details DrawL_buffers;

extern os_trfm trfmID;
extern os_trfm trfmrot30;
extern os_trfm trfmrot45;
extern os_trfm trfmrot60;
extern os_trfm trfmrot90;
extern os_trfm trfmrot270;
extern os_trfm trfmrot300;
extern os_trfm trfmrot315;
extern os_trfm trfmrot330;

/* exported functions */

extern void DrawL_BeginPathObject (draw_settings *dpars, osbool check_buffer);
extern void DrawL_EndPathObject (draw_settings *dpars, osbool check_buffer);
extern void DrawL_ClosePath (draw_settings *dpars);
extern void DrawL_Move (draw_settings *dpars, int x, int y);
extern void DrawL_Draw (draw_settings *dpars, int x, int y);
extern void DrawL_Line (draw_settings *dpars, int x1, int y1, int x2, int y2);

extern void DrawL_Square_C (draw_settings *dpars,
                              int x, int y, int size, osbool os_units);
extern void DrawL_Triangle_C (draw_settings *dpars, int x, int y, int size,
                      osbool up, osbool os_units);
extern void DrawL_Diamond_C (draw_settings *dpars, int x, int y,
                            int size, osbool os_units);
extern void DrawL_PlusC (draw_settings *dpars, int x, int y,
                         int size, osbool os_units);
extern void DrawL_CrossC (draw_settings *dpars, int x, int y,
                          int size, osbool os_units);

extern void DrawL_Circle_C (draw_settings *dpars, int xc, int yc,
                           int rad, osbool os_units);

extern draw_dash_pattern * DrawL_MakeDash (enum dashpattern pattern);
extern void DrawL_Rectangle ( draw_settings *dpars,
                      int x1, int y1, int x2, int y2, osbool os_units);
extern void DrawL_Trapezium (draw_settings *dpars,
                      int x1, int y1, int x2, int y2,
                      int x3, int y3, int x4, int y4,
                      osbool os_units);

extern void DrawL_Arc ( draw_settings *dpars, int xo, int yo, int radius,
                double startangle, double endangle, osbool os_units );
extern void DrawL_CircleSlice ( draw_settings *dpars, int xo, int yo, int radius,
                        double startangle, double endangle, osbool os_units );


extern void DrawL_TextObjectDU ( draw_settings *dpars,
                          char *text,
                          int x,
                          int y,
                          int fontsize,
                          int font_index,
                          font_f fhandle );

extern void DrawL_TextObject ( draw_settings *dpars,
                        char *text,
                        int x,
                        int y,
                        double fontsize,
                        int font_index,
                        font_f fhandle,
                        osbool os_units );

extern void DrawL_TransformedTextObjectDU ( draw_settings *dpars,
                                     char *text,
                                     int x,
                                     int y,
                                     int fontsize,
                                     int font_index,
                                     font_f fhandle,
                                     os_trfm *trfm );


extern void DrawL_TransformedTextObject ( draw_settings *dpars,
                                  char *text,
                                  int x,
                                  int y,
                                  double fontsize,
                                  int font_index,
                                  font_f fhandle,
                                  os_trfm *trfm,
                                  osbool os_units );

extern void DrawL_MakeHeader ( draw_settings *dpars, char *source_app );


extern void DrawL_Init (allocfn fn);

#endif






